const app = getApp();
import { addFavorite, delFavorite } from '../../../utils/requestApi.js';
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    goodsInfo: Object,
    prDid: String
  },

  /**
   * 组件的初始数据
   */
  data: {
    imgUrl: app.data.imgurl,
  },

  ready() {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    onAdd(e) {
      wx.setStorageSync('ctype', e.currentTarget.dataset.ctype)
      this.triggerEvent('open');
    },

    onCollect(e) {
      let { goodsInfo, prDid } = this.data;
      console.log(e)
      if (e.currentTarget.dataset.status) {
        delFavorite({ ProductId: prDid }).then(res => {
          if (res.data.Status == 'Success') {
            goodsInfo.IsFavorite = false
            this.setData({ goodsInfo })
          }
          wx.showToast({ icon: 'none', title: res.data.Message })
        })
      } else {
        addFavorite({ ProductId: prDid }).then(res => {
          if (res.data.Status == 'Success') {
            goodsInfo.IsFavorite = true
            this.setData({ goodsInfo })
          }
          wx.showToast({ icon: 'none', title: res.data.Message })
        })
      }
    }
  },
})
